﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using MYNAMESPACE;

namespace final_project
{
    public partial class EXchange_Currency : Form
    {
        public EXchange_Currency()
        {
            InitializeComponent();
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void EXchange_Currency_Load(object sender, EventArgs e)
        {

        }

        private void Exchange_Click(object sender, EventArgs e)
        {


            // Validating Start code

            if (this.ValidateChildren(ValidationConstraints.Enabled))
            {
                MessageBox.Show("All controls are valid!");
                //Logic to save...
            }
            else
            {
                MessageBox.Show("There are invalid controls on the form.");
                //Return user to form...
            }

            //Validating end code 



            Exchange_currency EC = new Exchange_currency();
           


            if (Value.Text.Length == null || From.Text.Length == 0 || TO.Text.Length == 0)
            {
                MessageBox.Show(" You Should Enter All Data ");
            }
            else
            {
                EC.set_currency(Int32.Parse(Value.Text));
                EC.set_current_currency(string.Format(From.Text));
                EC.set_other_currency(string.Format(TO.Text));
                string a, b;
                a = EC.get_current_currency();
                b = EC.get_other_currency();

                if (a == "EG" && b == "EURO")
                {
                    double x;
                    x = EC.Ex_from_EG_to_EURO();
                    MessageBox.Show("The Exchanged value will be :" + x.ToString());


                }
                else if (a == "EG" && b == "USD")
                {
                    double x = EC.Ex_from_EG_to_USD();
                    MessageBox.Show("The Exchanged value will be :" + x.ToString());
                }
                else if (a == "EURO" && b == "EG")
                {
                    double x = EC.Ex_from_EURO_to_EG();
                    MessageBox.Show("The Exchanged value will be :" + x.ToString());
                }
                else if (a == "USD" && b == "EG")
                {
                    double x = EC.Ex_from_USD_to_EG();
                    MessageBox.Show("The Exchanged value will be :" + x.ToString());

                }
                else
                {
                    MessageBox.Show("You Enter Wrong Data ");
                }

            }
        }

        private void Value_Validating(object sender, CancelEventArgs e)
        {

            if (string.IsNullOrEmpty(Value.Text))
            {

                e.Cancel = true;
                Value.Focus();
                errorProvider1.SetError(Value, "Value Must Be Entered !");

            }
            else if (!Regex.IsMatch(Value.Text, @"^\d+$"))
            {
                e.Cancel = true;
                errorProvider1.SetError(Value, "No Negative Numbers");

            }
            else
            {
                e.Cancel = false;
                errorProvider1.SetError(Value, "");
            }


        }

        private void From_Validating(object sender, CancelEventArgs e)
        {
            if (string.IsNullOrEmpty(From.Text))
            {

                e.Cancel = true;
                From.Focus();
                errorProvider1.SetError(From, "ID  Must Be Entered !");

            }

            else if (!Regex.IsMatch(From.Text, @"^\d{4}$"))
            {
                e.Cancel = true;
                errorProvider1.SetError(From, "Valid ID 4 Number");

            }



            else if (Regex.IsMatch(From.Text, @"^\d{4}$"))
            {
                e.Cancel = false;
                errorProvider1.SetError(From, "");

            }
            else { }
        }

        private void TO_Validating(object sender, CancelEventArgs e)
        {

            if (string.IsNullOrEmpty(TO.Text))
            {

                e.Cancel = true;
                TO.Focus();
                errorProvider1.SetError(TO, "ID Must Be Entered !");

            }

            else if (!Regex.IsMatch(TO.Text, @"^\d{4}$"))
            {
                e.Cancel = true;
                errorProvider1.SetError(TO, "Valid ID 4 Number");

            }



            else if (Regex.IsMatch(TO.Text, @"^\d{4}$"))
            {
                e.Cancel = false;
                errorProvider1.SetError(TO, "");

            }
            else { }

        }
    }
}
